package com.key.win.business.chat.dao;

import com.key.win.base.mapper.KeyWinMapper;
import com.key.win.business.chat.vo.ImMessageNumVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ImMessageNumDao extends KeyWinMapper<ImMessageNumVo> {

    @Select({"SELECT a.from_User_Id, a.target_id, a.target ,CASE a.target WHEN 0 THEN ( SELECT u.`nick_name` FROM sys_user u WHERE u.id = a.from_User_Id ) WHEN 1 THEN ( SELECT u.`name` FROM im_group u WHERE u.id = a.from_User_Id ) ELSE '系统' END AS `name`, COUNT(1) AS num FROM im_message_detail a WHERE a.to_user_id =  #{toUserId} AND a. STATUS = 0 GROUP BY a.from_user_id, a.target, a.target_id"})
    List<ImMessageNumVo> findUnreadMessage(String toUserId);
}
